/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.football.lottery.ui;

import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JTable;

/**
 *
 * @author JingWen.Wen
 */
public class CheckboxCellEditor extends DefaultCellEditor implements ItemListener
{
  CheckboxPanel panel;

    public CheckboxCellEditor(JCheckBox checkBox, CheckboxPanel panel)
    {
      super(checkBox);
      this.panel = panel;
      JCheckBox[] boxes = panel.getBoxes();
      for (int i = 0; i < boxes.length; i++)
      {
        boxes[i].addItemListener(this);
      }
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
    {
      if (value instanceof String)
      {
        panel.setValue((String) value);
      }
      return panel;
    }

    @Override
    public Object getCellEditorValue()
    {
      return panel.getValue();
    }

    @Override
    public void itemStateChanged(ItemEvent e)
    {
      super.fireEditingStopped();
    }
}
